package com.okyai.qa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.okyai.common.core.text.Convert;
import com.okyai.qa.domain.QuestionnaireQuestions;
import com.okyai.qa.mapper.QuestionnaireQuestionsMapper;
import com.okyai.qa.service.IQuestionnaireQuestionsService;

/**
 * 问卷题目Service业务层处理
 * 
 * @author okyai
 * @date 2021-03-16
 */
@Service
public class QuestionnaireQuestionsServiceImpl implements IQuestionnaireQuestionsService 
{
    @Autowired
    private QuestionnaireQuestionsMapper questionnaireQuestionsMapper;

    /**
     * 查询问卷题目
     * 
     * @param questionsId 问卷题目ID
     * @return 问卷题目
     */
    @Override
    public QuestionnaireQuestions selectQuestionnaireQuestionsById(Long questionsId)
    {
        return questionnaireQuestionsMapper.selectQuestionnaireQuestionsById(questionsId);
    }

    /**
     * 查询问卷题目列表
     * 
     * @param questionnaireQuestions 问卷题目
     * @return 问卷题目
     */
    @Override
    public List<QuestionnaireQuestions> selectQuestionnaireQuestionsList(QuestionnaireQuestions questionnaireQuestions)
    {
        return questionnaireQuestionsMapper.selectQuestionnaireQuestionsList(questionnaireQuestions);
    }

    /**
     * 新增问卷题目
     * 
     * @param questionnaireQuestions 问卷题目
     * @return 结果
     */
    @Transactional
    @Override
    public int insertQuestionnaireQuestions(QuestionnaireQuestions questionnaireQuestions)
    {
        int rows = questionnaireQuestionsMapper.insertQuestionnaireQuestions(questionnaireQuestions);
        insertQuestionnaireAnswers(questionnaireQuestions);
        return rows;
    }

    /**
     * 修改问卷题目
     * 
     * @param questionnaireQuestions 问卷题目
     * @return 结果
     */
    @Transactional
    @Override
    public int updateQuestionnaireQuestions(QuestionnaireQuestions questionnaireQuestions)
    {
        questionnaireQuestionsMapper.deleteQuestionnaireAnswersByQuestionsId(questionnaireQuestions.getQuestionsId());
        insertQuestionnaireAnswers(questionnaireQuestions);
        return questionnaireQuestionsMapper.updateQuestionnaireQuestions(questionnaireQuestions);
    }

    /**
     * 删除问卷题目对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteQuestionnaireQuestionsByIds(String ids)
    {
        questionnaireQuestionsMapper.deleteQuestionnaireAnswersByQuestionsIds(Convert.toStrArray(ids));
        return questionnaireQuestionsMapper.deleteQuestionnaireQuestionsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除问卷题目信息
     * 
     * @param questionsId 问卷题目ID
     * @return 结果
     */
    @Override
    public int deleteQuestionnaireQuestionsById(Long questionsId)
    {
        questionnaireQuestionsMapper.deleteQuestionnaireAnswersByQuestionsId(questionsId);
        return questionnaireQuestionsMapper.deleteQuestionnaireQuestionsById(questionsId);
    }

    /**
     * 新增答案信息
     * 
     * @param questionnaireQuestions 问卷题目对象
     */
    public void insertQuestionnaireAnswers(QuestionnaireQuestions questionnaireQuestions)
    {
    	/*
        List<QuestionnaireAnswers> questionnaireAnswersList = questionnaireQuestions.getQuestionnaireAnswersList();
        Long questionsId = questionnaireQuestions.getQuestionsId();
        if (StringUtils.isNotNull(questionnaireAnswersList))
        {
            List<QuestionnaireAnswers> list = new ArrayList<QuestionnaireAnswers>();
            for (QuestionnaireAnswers questionnaireAnswers : questionnaireAnswersList)
            {
                questionnaireAnswers.setQuestionsId(questionsId);
                list.add(questionnaireAnswers);
            }
            if (list.size() > 0)
            {
                questionnaireQuestionsMapper.batchQuestionnaireAnswers(list);
            }
        }
        */
    }
}
